const Mock = require('mockjs');
const getQuestionList = require('./data/getQuestionList');
const getComponentList = require('./data/getComponentList')
const Random = Mock.Random
module.exports = [
  {
    url: '/api/question',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id()
        }
      }
    }
  },
  {
    url: '/api/question/:id',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          desc:'问卷描述111',
          js: '',
          css: '',
          isPublished: true,
          componentList: getComponentList()
        }
      }
    }
  },
  // 列表
  {
    url: '/api/question',
    method: 'get',
    response(ctx) {
      const isDeleted = ctx.url.indexOf('isDeleted=true') >= 0
      const isStar = ctx.url.indexOf('isStar=true') >= 0
      const pageSize = parseInt(ctx.query.pageSize) || 10
      const page = parseInt(ctx.query.page)
      return {
        errno: 0,
        data: {
          list: getQuestionList({len: pageSize, isDeleted, isStar}),
          total: 100
        }
      }
    }
  },
  {
    url: '/api/question/:id',
    method: 'patch',
    response() {
      return {
        errno: 0
      }
    }
  },
  // copy
  {
    url: '/api/question/duplicate/:id',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id()
        }
      }
    }
  },
  {
    url: '/api/question',
    method: 'delete',
    response() {
      return {
        errno: 0
      }
    }
  }
]